package com.xiaolin.util;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @ClassName TestIterator
 * @Description TODO
 * @Detail detail
 * @Author MyPC
 * @Date 2020/9/26
 * @Version 1.0
 */
public class TestIterator {
    public static void main(String[] args) {
        List<Coffee> list=new ArrayList<>();
        Coffee c1=new Coffee("拿铁",15);
        Coffee c2=new Coffee("卡布",16);
        Coffee c3=new Coffee("普通咖啡",10);
        list.add(c1);
        list.add(c2);
        list.add(c3);
        Iterator<Coffee> iterator = list.iterator();
        while (iterator.hasNext()){
            //第一次使用next方法时是获取到第一个元素，之后是获取到下一个元素
            System.out.println(iterator.next().getName());
        }
    }
}

class Coffee{
    private String name;
    private int price;

    Coffee(String name,int price){
        this.name=name;
        this.price=price;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getPrice() {
        return price;
    }

    public void setPrice(int price) {
        this.price = price;
    }
}
